package xjtu.sad.zbsj.user.login.dao;

import xjtu.sad.zbsj.user.login.LoginDto;
import xjtu.sad.zbsj.user.login.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

/**
 * @author lkm
 */
public interface LoginDao {

    @Select("select count(user_name) from t_user_info where user_name = #{u_id} and passwd= #{u_pwd}")
    int findCountByUserIdAndPassword(LoginDto dto);

    @Select("select user_id,user_name,gender from t_user_info where user_id = #{u_id}")
    User findUserById(String u_id);

    @Select("select r_id from t_user_info where user_id =#{u_id} order by r_id desc limit 1")
    String getRole(String u_id);

    @Select("select r_id from t_user_info where user_name =#{u_id}  order by r_id desc limit 1")
    String getRole2(LoginDto dto);

    @Select("select r_id from t_user_info where mail =#{u_eml}  order by r_id desc limit 1")
    String getRole3(LoginDto dto);

   // @Insert("insert into log(log_id,u_id,t_id,p_id) values(#{l_id},#{u_id},#{t_id},#{p_id})")
   // void addLogTime(LoginDto dto);

    @Select("select user_id from t_user_info WHERE user_name = #{u_id} AND passwd = #{u_pwd}")
    String getUser(LoginDto dto);

    @Select("select user_id from t_user_info where mail = #{eml}")
    String getUserId(String eml);

    @Select("select passwd from t_user_info where mail = #{eml}")
    String getUserPwd(String eml);

    @Select("select lpad(ifnull(max(convert(substring(log_id from 10),unsigned)),0)+1,4,'0') from log where log_id like concat(#{prefix},'%')")
    String findLoginNewNum(String prefix);

    @Select("select user_id from t_user_info where user_name = #{u_id}")
    String findUid(LoginDto dto);
}